path1      = spm_select(1,'dir','please data1 dir');
file1         = dir([path1,filesep, '*.mat']);
%�����һ�����ݵ�ַ���ļ���

for i=1:length(file1) 
    load([path1,filesep,file1(i).name]);%�������
    Z(isnan(Z)) = 0;%��NaNɾ��
    Z(Z==Inf)    = 0;%��������ɾ��
    Z(Z==-Inf)   = 0;%�Ѹ�����ɾ��
    all_default_se1(:,:,i)=Z;%
    clear Z  %��Z���     
end  
%�����һ�鱻�ԡ�

path2     = spm_select(1,'dir','please data2 dir');
file2         = dir([path2,filesep, '*.mat']);
%����ڶ������ݵ�ַ���ļ���
for i=1:length(file2)
    load([path2,filesep,file2(i).name]);%�������
    Z(isnan(Z)) = 0;%��NaNɾ��
    Z(Z==Inf)    = 0;%��������ɾ��
    Z(Z==-Inf)   = 0;%�Ѹ�����ɾ�� 
    all_default_se2(:,:,i)=Z;%
    clear Z  %��Z���     
end
clear i;
%����ڶ��鱻��
%%
[m,n,p]=size(all_default_se2);

ccp1=mean(all_default_se1.*all_default_se2,3);%�������Ҫ��ֵ��


for i2=1:p
    for i1=1:p
        cccpp(:,:,i1+(i2-1)*p)=all_default_se1(:,:,i1).*all_default_se2(:,:,i2);
        index(i1+(i2-1)*p,1)=i1;
        index(i1+(i2-1)*p,2)=i2;
    end
end

h = waitbar(0,'please wait..');
for sub_nom=1:p
    index_ii=find(index(:,1)==sub_nom & index(:,2)==sub_nom);
    index_ij=find(index(:,1)==sub_nom & index(:,2)~=sub_nom);
    index_ji=find(index(:,1)~=sub_nom & index(:,2)==sub_nom);
    %�ҵ�������һ���Ե�Ŀ¼
    
    mat_ii=cccpp(:,:,index_ii);
    mat_ij=cccpp(:,:,index_ij);
    mat_ji=cccpp(:,:,index_ji);
    %�õ����ڼ���ľ���
    
    mat_iji=cat(3,mat_ij,mat_ji);
    q=size(mat_iji,3);
    mat_iii=repmat(mat_ii,[1,1,q]);
    %׼����ҪŪ����ֵ
    
    p_value_3d=mat_iji-mat_iii;
    p_value_3d(p_value_3d>0)=1;
    p_value_3d(p_value_3d~=1)=0;
    p_value(:,:,sub_nom)=(sum(p_value_3d,3))/(2*(p-1));
    p_value(p_value==0)=0.01;
    %�������һ���Ե�
    waitbar(sub_nom/p,h,[num2str(sub_nom),'/',num2str(p)]); 
end
A_p_value=mean(p_value,3);
dp1=sum(-1*log(p_value),3);
%����������Ҫ��ֵ
close(h);
 
    